package com.bytech.common.biz.enums;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.bytech.common.utils.StringUtils;
import com.google.common.collect.ImmutableList;
import lombok.Getter;

/**
 * @Author Zhao
 * @Create 2021/8/13 15:32
 */
@Getter
public enum CommonStatusEnum {
    UNKNOWN("unknown", "未知"),
    NORMAL("normal", "正常"),
    FORBID("forbid", "禁用"),
    DELETED("deleted", "已删除"),
    ;

    private final String value;
    private final String desc;

    CommonStatusEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    private static final Map<String, CommonStatusEnum> map = new HashMap<>(CommonStatusEnum.values().length);

    static {
        for (CommonStatusEnum e : CommonStatusEnum.values()) {
            map.put(e.value, e);
        }
    }

    public static CommonStatusEnum of(String state) {
        return Optional.ofNullable(map.get(state)).orElse(UNKNOWN);
    }

    public static List<CommonStatusEnum> validValues() {
        return ImmutableList.of(NORMAL, FORBID, DELETED);
    }
}
